"""分析同环比视图函数模块"""
from flask import request

from air_web.web_flask.bll.analysis_bll import AnalysisBll
from air_web.web_flask.common.constants import PAGE_NO, PAGE_SIZE
from air_web.web_flask.common.validator import (
    T_CHINESE,
    T_DATE,
    T_INT,
    T_LIST,
    T_STR,
    Fields,
    with_validator,
)
from air_web.web_flask.views.base_page import BasePage


class AnalysisPageValidationFields:
    huanbi_fields = [
        Fields("area_code", T_STR, must=False),
        Fields("cons_no", T_STR, must=False),
        Fields("type_id", T_INT, must=False),
        Fields("end_date_1", T_DATE, must=True),
        Fields("end_date_2", T_DATE, must=True),
        Fields("days", T_INT, must=True),
    ]

    tongbi_fields = [
        Fields("area_code", T_STR, must=False),
        Fields("cons_no", T_STR, must=False),
        Fields("type_id", T_INT, must=False),
        Fields("start_date", T_DATE, must=True),
        Fields("end_date", T_DATE, must=True),
    ]

    load_resolve_fields = [
        Fields("cons_no", T_STR, must=False),
        Fields("start_date", T_DATE, must=True),
        Fields("type_code", T_INT, must=False),
        Fields("area_code", T_STR, must=False),
        # Fields("end_date", T_DATE, must=True)
    ]


class AnalysisPage(BasePage):
    """总览页面视图函数类"""

    @classmethod
    @with_validator(request, AnalysisPageValidationFields.huanbi_fields)
    def air_huanbi(cls):
        validation_data = request.validation_data
        result = AnalysisBll().get_air_huanbi(validation_data)
        return cls.return_common_func(result)

    @classmethod
    @with_validator(request, AnalysisPageValidationFields.tongbi_fields)
    def air_tongbi(cls):
        validation_data = request.validation_data
        result = AnalysisBll().get_air_tongbi(validation_data)
        return cls.return_common_func(result)
